#ifndef SIGNALMANAGER_HPP
#define SIGNALMANAGER_HPP
#include "IOManager.hpp"

//////////////////////////////////////////////////////////////////////////////

class Event
{
public:
	virtual ~Event();
};

class SignalEvent
	:public Event
{
public:
	SignalEvent(int signal);
	int signal;
};

class JobFinishedEvent
	:public Event
{
public:
	JobFinishedEvent(int id, PseudoTerminal *pty, int result, ShellState *state);

	int id;
	PseudoTerminal *pty;
	int result;
	ShellState *state;
};

class ExitShellEvent
	:public Event
{
public:
	ExitShellEvent(int code);
	
	int code;
};

class CrashTestEvent
	:public Event
{
public:
	CrashTestEvent();
};

class FileTransferFinishedEvent
	:public Event
{
};

//////////////////////////////////////////////////////////////////////////////

class EventManager
{
public:
	EventManager();
	~EventManager();
	
	void addEvent(Event *event);
	void notify();
	Event *nextEvent();
	void waitForEvents();
	void setNotifyPipe(int fd);
	
protected:
	pthread_mutex_t lock;
	pthread_cond_t condition;
	
	bool waking;
	int notifyPipe;
	deque<Event*> pendingEvents;
};

extern EventManager *eventManager;

#endif
